﻿using System;

namespace ConsoleDemo
{
    internal class DisposeExample : IDisposable
    {
        bool disposed = false;  //释放状态

        //公共 Dispose 方法
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        //析构函数
        ~DisposeExample()
        {
            Dispose(false);
        }

        //分解释放
        protected virtual void Dispose(bool disposing)
        {
            if (disposed == false)
            {
                if (disposing == true)
                {
                    // Dispose the managed resources.
                }
                // Dispose the unmanaged resources.
            }
            disposed = true;
        }

    }
}

